package com.codename1.samples;


import static com.codename1.ui.CN.*;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import com.codename1.ui.Toolbar;
import com.codename1.ui.Container;
import com.codename1.ui.Tabs;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.table.TableLayout;


/**
 * Test case for https://github.com/codenameone/CodenameOne/issues/3023
 * This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose 
 * of building native mobile applications using Java.
 */
public class NestedTabsTest3023 {

    private Form current;
    private Resources theme;

    public void init(Object context) {
        // use two network threads instead of one
        updateNetworkThreadCount(2);

        theme = UIManager.initFirstTheme("/theme");

        // Enable Toolbar on all Forms by default
        Toolbar.setGlobalToolbar(true);

        // Pro only feature
        Log.bindCrashProtection(true);

        addNetworkErrorListener(err -> {
            // prevent the event from propagating
            err.consume();
            if(err.getError() != null) {
                Log.e(err.getError());
            }
            Log.sendLogAsync();
            Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
        });        
    }
    
    public void start() {
        if(current != null){
            current.show();
            return;
        }
        Form f = new Form("custom tabs", new BorderLayout());
        Tabs outerTabs = new Tabs();
        
        Tabs tabs = new Tabs();
        
        tabs.addTab("inner1", new Label("content1"));
        tabs.addTab("inner2", new Label("content2"));
        tabs.addTab("inner3", new Label("content3"));
        
        Container tabsCont = tabs.getTabsContainer();
        
        TableLayout newLayout = new TableLayout(1, 2);
        tabsCont.getComponentAt(0).setHidden(true);
        tabsCont.setLayout(newLayout);
        
        newLayout.addLayoutComponent(newLayout.cc(0,0).widthPercentage(50), tabsCont.getComponentAt(1), tabsCont);
        newLayout.addLayoutComponent(newLayout.cc(0,1).widthPercentage(50), tabsCont.getComponentAt(2), tabsCont);
        
        outerTabs.addTab("outer1", new Container());
        outerTabs.addTab("outer2", tabs);
        
        
        f.addComponent(BorderLayout.CENTER, outerTabs);
        f.show();
    }

    public void stop() {
        current = getCurrentForm();
        if(current instanceof Dialog) {
            ((Dialog)current).dispose();
            current = getCurrentForm();
        }
    }
    
    public void destroy() {
    }

}
